#!/usr/local/bin/perl -w
#-d:NYTProf
use strict;
use warnings;
use utf8;
use lib '../lib';
use NG::Sys::App 'NG::Sys::Loop::Run';
use NG::Chat::Client::Interactive;

my $app = new NG::Sys::App(logger=>"screen");
#$app->die_to_logger;
#$app->warn_to_logger;

$app->run;

sub on_prepare_loop {
	my ($app) = @_;

	if($app->{'http-connect'} && !$app->arg->{sock}){
		require NG::Chat::Client::Http;
		$app->{'client-connect'} = NG::Chat::Client::Http::Create($app);
	}elsif($app->{'sock-connect'}){
		require NG::Chat::Client::Sock;
		$app->{'client-connect'} = NG::Chat::Client::Sock::Create($app);
	}else{
		die "need connect";
	}

	$app->{'client-input'} = new NG::Chat::Client::Interactive($app->{'client-connect'});
}
sub on_process {
	my ($app) = @_;
	EV::loop;
}
sub on_after_loop {
	my ($app) = @_;
	(delete $app->{'client-input'})->cleanup;
	(delete $app->{'client-connect'})->cleanup;
}
